package cn.flying.cloud.flow.controller;

import javax.annotation.Resource;

import java.util.Objects;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import cn.flying.cloud.base.common.vo.PageRequest;
import cn.flying.cloud.base.common.vo.PageResponse;
import cn.flying.cloud.base.common.vo.Rt;
import cn.flying.cloud.flow.bo.FwProcExceptionBo;
import cn.flying.cloud.flow.service.FwProcExceptionService;

/**
 * 异常信息表 前端控制器
 *
 * @author: admin
 * @date: 2024-10-28 20:09:38
 * @version: 1.0
 */
@RestController
@RequestMapping("/flow/proc/exception")
public class FwProcExceptionController {
    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Resource
    private FwProcExceptionService fwProcExceptionService;

    /**
     * 分页查询异常信息表数据
     *
     * @param request 参数
     * @return
     */
    @PostMapping("page")
    public PageResponse<FwProcExceptionBo> page(@RequestBody PageRequest<FwProcExceptionBo> request) {
        return fwProcExceptionService.getPageList(request);
    }

    /**
     * 列表查询异常信息表数据
     *
     * @param param 参数
     * @return
     */
    @PostMapping("list")
    public Rt<?> list(@RequestBody FwProcExceptionBo param) {
        return Rt.success(fwProcExceptionService.getList(param));
    }

    /**
     * 查询异常信息表详情数据
     *
     * @param param 参数
     * @return
     */
    @PostMapping("detail")
    public Rt<?> detail(FwProcExceptionBo param) {
        return Rt.success(fwProcExceptionService.getOneObj(param));
    }

    /**
     * 根据主键ID查询异常信息表详情数据
     *
     * @param id 主键ID
     * @return
     */
    @PostMapping("getById")
    public Rt<?> getById(Long id) {
        return Rt.success(fwProcExceptionService.getObjById(id));
    }

    /**
     * 保存异常信息表数据
     *
     * @param param 参数
     * @return
     */
    @PostMapping("save")
    public Rt<?> save(@RequestBody FwProcExceptionBo param) {
        if (Objects.isNull(param.getId())) {
            // 新增
            fwProcExceptionService.createObj(param);
        } else {
            // 更新
            fwProcExceptionService.updateObj(param);
        }
        return Rt.success("保存成功！");
    }

    /**
     * 删除异常信息表数据
     *
     * @param param 参数
     * @return
     */
    @PostMapping("delete")
    public Rt<?> delete(FwProcExceptionBo param) {
        fwProcExceptionService.deleteObj(param);
        return Rt.success("删除成功！");
    }

    /**
     * 根据主键ID删除异常信息表数据
     *
     * @param id 主键ID
     * @return
     */
    @GetMapping("deleteById/{id}")
    public Rt<?> deleteById(@PathVariable("id") Long id) {
        fwProcExceptionService.deleteById(id);
        return Rt.success("删除成功！");
    }
}
